package com.yonyou.brigade.openapi.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.order_center.service.IExpenseStatusService;
import com.yonyou.brigade.util.resultutil.Msg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/status")
public class ExpenseStatusController {

    private static Logger logger = LoggerFactory.getLogger(ExpenseStatusController.class);

    @Autowired
    IExpenseStatusService expenseStatusService;

    /**
     *通过报销单pk获取订单报销状态接口
     * @param param
     * @return
     */
    @RequestMapping("/getOrderStatusByPK")
    public Msg getOrderStatusByPK(@RequestBody JSONObject param){
        Msg res = null;
        res = expenseStatusService.getOrderStatusByPK(param);
        return res;
    }
    /**
     * 修改报销状态
     * @param params
     * @return
     */
    @RequestMapping("/setStatus")
    public Msg setStatus(HttpServletRequest request, @RequestBody JSONArray params){
        String tenant = request.getParameter("tenantId");
        logger.info("setStatus tenantId:" + tenant + " params:" + JSON.toJSONString(params));
        Msg res = null;
        res = expenseStatusService.setStatus(params, tenant);
        return res;
    }

    /**
     *新增订单与报销单关联关系
     * @param params
     * @return
     */
    @RequestMapping("/addConnection")
    public Msg addConnection(HttpServletRequest request, @RequestBody JSONArray params){
        boolean isRollBack = Boolean.valueOf(request.getParameter("isRollBack"));
        String tenant = request.getParameter("tenantId");
        logger.info("addConnection tenantId:" + tenant + " params:" + JSON.toJSONString(params));
        Msg res = null;
        res = expenseStatusService.addConnection(params, isRollBack, tenant);
        return res;
    }

    /**
     * 修改订单与报销单关联关系
     * @param params
     * @return
     */
    @RequestMapping("/updateConnection")
    public Msg updateConnection(HttpServletRequest request, @RequestBody JSONArray params){
        boolean isRollBack = Boolean.valueOf(request.getParameter("isRollBack"));
        String tenant = request.getParameter("tenantId");
        logger.info("updateConnection tenantId:" + tenant + " params:" + JSON.toJSONString(params));
        Msg res = null;
        res = expenseStatusService.updateConnection(params,isRollBack, tenant);
        return res;
    }

    /**
     *取消订单与报销单关联关系
     * @param params
     * @return
     */
    @RequestMapping("/cancelConnection")
    public Msg cancelConnection(HttpServletRequest request, @RequestBody JSONArray params){
        boolean isRollBack = Boolean.valueOf(request.getParameter("isRollBack"));
        String tenant = request.getParameter("tenantId");

        Msg res = null;
        res = expenseStatusService.cancelConnection(params, isRollBack, tenant);
        return res;
    }
}
